package com.example.foobar.controller;

import com.example.foobar.business.service.DidiPromotionService;
import com.example.foobar.entity.DidiPromotion;
import com.example.foobar.dao.service.DidiPromotionDaoService;
import lombok.extern.slf4j.Slf4j;
import com.example.foobar.param.DidiPromotionPageParam;
import io.geekidea.springbootplus.framework.common.controller.BaseController;
import io.geekidea.springbootplus.framework.common.api.ApiResult;
import io.geekidea.springbootplus.framework.core.pagination.Paging;
import io.geekidea.springbootplus.framework.log.annotation.Module;
import io.geekidea.springbootplus.framework.log.annotation.OperationLog;
import io.geekidea.springbootplus.framework.log.enums.OperationLogType;
import io.geekidea.springbootplus.framework.core.validator.groups.Add;
import io.geekidea.springbootplus.framework.core.validator.groups.Update;
import org.springframework.validation.annotation.Validated;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 滴滴推广位 控制器
 *
 * @author 郑英奔
 * @since 2021-11-16
 */
@Slf4j
@RestController
@RequestMapping("/didiPromotion")
@Module("foobar")
@Api(value = "滴滴推广位API", tags = {"滴滴推广位"})
public class DidiPromotionController extends BaseController {

    @Autowired
    private DidiPromotionService didiPromotionService;

    /**
     * 添加滴滴推广位
     */
    @PostMapping("/add")
    @OperationLog(name = "添加滴滴推广位", type = OperationLogType.ADD)
    @ApiOperation(value = "添加滴滴推广位", response = ApiResult.class)
    public ApiResult<Boolean> addDidiPromotion(@Validated(Add.class) @RequestBody DidiPromotion didiPromotion) throws Exception {
        boolean flag = didiPromotionService.saveDidiPromotion(didiPromotion);
        return ApiResult.result(flag);
    }

    /**
     * 修改滴滴推广位
     */
    @PostMapping("/update")
    @OperationLog(name = "修改滴滴推广位", type = OperationLogType.UPDATE)
    @ApiOperation(value = "修改滴滴推广位", response = ApiResult.class)
    public ApiResult<Boolean> updateDidiPromotion(@Validated(Update.class) @RequestBody DidiPromotion didiPromotion) throws Exception {
        boolean flag = didiPromotionService.updateDidiPromotion(didiPromotion);
        return ApiResult.result(flag);
    }

    /**
     * 删除滴滴推广位
     */
    @PostMapping("/delete/{id}")
    @OperationLog(name = "删除滴滴推广位", type = OperationLogType.DELETE)
    @ApiOperation(value = "删除滴滴推广位", response = ApiResult.class)
    public ApiResult<Boolean> deleteDidiPromotion(@PathVariable("id") Long id) throws Exception {
        boolean flag = didiPromotionService.deleteDidiPromotion(id);
        return ApiResult.result(flag);
    }

    /**
     * 获取滴滴推广位详情
     */
    @GetMapping("/info/{id}")
    @OperationLog(name = "滴滴推广位详情", type = OperationLogType.INFO)
    @ApiOperation(value = "滴滴推广位详情", response = DidiPromotion.class)
    public ApiResult<DidiPromotion> getDidiPromotion(@PathVariable("id") Long id) throws Exception {
        DidiPromotion didiPromotion = didiPromotionService.getById(id);
        return ApiResult.ok(didiPromotion);
    }

    /**
     * 滴滴推广位分页列表
     */
    @PostMapping("/getPageList")
    @OperationLog(name = "滴滴推广位分页列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "滴滴推广位分页列表", response = DidiPromotion.class)
    public ApiResult<Paging<DidiPromotion>> getDidiPromotionPageList(@Validated @RequestBody DidiPromotionPageParam didiPromotionPageParam) throws Exception {
        Paging<DidiPromotion> paging = didiPromotionService.getDidiPromotionPageList(didiPromotionPageParam);
        return ApiResult.ok(paging);
    }

    /**
     * 滴滴推广位列表
     */
    @GetMapping("/getList")
    @OperationLog(name = "滴滴推广位列表", type = OperationLogType.PAGE)
    @ApiOperation(value = "滴滴推广位列表", response = DidiPromotion.class)
    public ApiResult<List<DidiPromotion>> getList() {
        List<DidiPromotion> paging = didiPromotionService.getList();
        return ApiResult.ok(paging);
    }

}

